/**
 * @file     readBinaryWatch.js
 * @brief    [401. 二进制手表](https://leetcode.cn/problems/binary-watch/description/)
 * @author   Zhu
 * @date     2023-02-12 23:06
 */

/**
 * 高4位表示时间，低6位表示分钟
 * @param {number} turnedOn
 * @return {string[]}
 */
var readBinaryWatch = function (turnedOn) {
    const ans = [];
    for (let i = 0; i < 1024; i++) {
        if (oneCount(i) === turnedOn) {
            const hours = i >> 6;
            const minutes = i & 63;
            if (hours < 12 && minutes < 60) {
                ans.push(hours + ':' + minutes.toString().padStart(2, '0'));
            }
        }
    }

    return ans;

    function oneCount(num) {
        return num.toString(2).split('0').join('').length;
        // let count = 0;
        // while (num > 0) {
        //     if ((num & 1) === 1) count++;
        //     num >> 1;
        // }
        // return count;
    }
};
